package com.coders.android.services;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.coders.android.hibernate.dto.Taxi;
import com.coders.android.spring.service.TaxiService;

@Path("android/taxi")
@Component
public class TaxiServiceREST {

	@Autowired
	TaxiService taxiService;
	
	@Produces(MediaType.APPLICATION_JSON)
	@Path("registrar/{imei}/{latitud}/{longitud}")
	@GET
	public String insertar(
			@PathParam( "imei" ) String imei,
			@PathParam( "latitud" ) double latitud,
			@PathParam( "longitud" ) double longitud ) {
		
		try {
			taxiService.insertar( new Taxi(imei, latitud, longitud) );
			return "OK";
			
		} catch (Exception e) {
			//e.printStackTrace();
			return "FAIL: " + e.getMessage();
		}
	}
	
	@Produces(MediaType.APPLICATION_JSON)
	@Path("eliminar/{imei}")
	@GET	
	public String eliminar( @PathParam( "imei" ) String imei ) {
	
		try {
			taxiService.eliminar( imei );
			return "OK";
		} catch (Exception e) {
			//e.printStackTrace();
			return "FAIL: " + e.getMessage();
		}
	}
}
